#!/usr/bin/python

from decimal import *
import os


start =1000000
step  =10000


tab = range(start,5*start,step)

os.system("rm -rf simulation_mono_bloc.out")
os.system("rm -rf simulation_poly_bloc.out")

os.system("touch simulation_poly_bloc.out")
os.system("touch simulation_mono_bloc.out")

prog ="../main_surcout_grossier"
os.system("cd ..")
os.system("make clean")

#simulation avec monoallocation
for x in tab:
    cmd = prog + " " +str(x) +" 1 >> simulation_mono_bloc.out"
    os.system(cmd)
    print cmd;


#simulation avec polyallocation
for x in tab:
    cmd = prog +" "+str(x) +" 0 >> simulation_poly_bloc.out"
    os.system(cmd)
    print cmd;


#
f_in_mono = open('../output/simulation_mono_bloc.out','r')
f_in_poly = open('../output/simulation_poly_bloc.out','r')
f_out_mono= open('../data/data_monobloc.dat','w+')
f_out_poly= open('../data/data_polybloc.dat','w+')

#
f_out_mono.write("nbBlocs VmSize VmPeak VmLib VmExe VmData VmRSS VmHWM\n")
f_out_poly.write("nbBlocs VmSize VmPeak VmLib VmExe VmData VmRSS VmHWM\n")

#les lignes de sortie
lines_mono= f_in_mono.readlines()
lines_poly= f_in_poly.readlines()

#postraitement
for line in lines_mono:
    if(line[0]=='#'):
        f_out_mono.write(line.replace('#',''));

for line in lines_poly:
    if(line[0]=='#'):
        f_out_poly.write(line.replace('#',''));

f_in_mono.close()
f_out_mono.close()
f_in_poly.close()
f_out_poly.close()


os.system("gnuplot ../gnuplot/plot_surcout_polyBloc.gp")
